package com.example.customer.controller;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.common.PageUtils;
import com.example.common.R;
import com.example.common.dto.BaseReturnDto;
import com.example.customer.entity.CustomerDO;
import com.example.customer.service.CustomerService;
import com.example.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tc
 * @since 2022-10-28
 */
@RestController
public class CustomerController {
    @Autowired
    CustomerService customerService;
    RedisUtils redisUtils;

    @GetMapping("/customer")
//    @CrossOrigin(origins = "*")
    public BaseReturnDto<?> list(@RequestParam (defaultValue = "1") Integer pageNum,
                  @RequestParam (defaultValue = "4")Integer pageSize,
                  @RequestParam(value = "search",required = false,defaultValue = "") String search){
          PageUtils page  = customerService.Querylist(pageNum,pageSize,search);
          return  BaseReturnDto.success().data(page);
    }

    @GetMapping("/customer/add")
    public BaseReturnDto<String> add(@RequestParam("name")String name,@RequestParam(value = "sex",required = false)String sex,@RequestParam(value = "pwd",required = false)String pwd,@RequestParam("address") String address, @RequestParam(value = "email",required = false) String email){
        return customerService.addCustomer(name,sex,pwd,address,email);
    }

    @GetMapping("/customer/export")
    public BaseReturnDto<String> export(HttpServletRequest req,HttpServletResponse resp){
        return customerService.exportCustomer(req,resp);
    }

}

